package top.korori.api.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import top.korori.common.model.Result;
import top.korori.sv.entity.bo.SvUserAvatarBo;
import top.korori.sv.entity.bo.SvUserEditBo;
import top.korori.sv.entity.vo.SvUserAreaTreeVo;
import top.korori.sv.entity.vo.SvUserInfoVo;
import top.korori.sv.service.SvUserAreaService;
import top.korori.sv.service.SvUserService;

import java.util.List;

/**
 * 短视频前台用户 前端控制器
 *
 * @author korori
 */
@Api(tags = "用户信息接口")
@RestController
@RequestMapping("/sv/user")
@RequiredArgsConstructor
public class SvUserController {

    private final SvUserAreaService svUserAreaService;

    private final SvUserService svUserService;

    @ApiOperation("获取用户地址选择数据")
    @GetMapping("/areaTree")
    public Result<List<SvUserAreaTreeVo>> areaTree() {
        List<SvUserAreaTreeVo> tree = svUserAreaService.tree();
        return Result.ok(tree);
    }

    @ApiOperation("修改用户信息")
    @PutMapping("/editInfo")
    public Result<Void> editInfo(@RequestBody @Validated SvUserEditBo svUserEditBo) {
        svUserService.editInfo(svUserEditBo);
        return Result.ok();
    }

    @ApiOperation(value = "Base64头像上传", notes = "仅支持png,jpg,jpeg类型图片")
    @PostMapping("/uploadAvatar")
    public Result<Void> uploadAvatar(@RequestBody @Validated SvUserAvatarBo svUserAvatarBo) {
        svUserService.uploadAvatar(svUserAvatarBo.getBase64());
        return Result.ok();
    }

    @ApiOperation(value = "文件头像上传",notes = "仅支持png,jpg,jpeg类型图片")
    @PostMapping("/uploadAvatarFile")
    public Result<Void> uploadAvatarFile(@RequestPart MultipartFile file){
        svUserService.uploadAvatarFile(file);
        return Result.ok();
    }


    @ApiOperation("获取当前登录用户信息")
    @GetMapping("/getLoginInfo")
    public Result<SvUserInfoVo> getLoginInfo() {
        SvUserInfoVo svUserInfoVo = svUserService.getLoginInfo();
        return Result.ok(svUserInfoVo);
    }


}




















